import {LangData} from "./data";
import {useIndexStore} from "../../store";
import {KeyLangData} from "./data_key";

export function GetLang(K:string):string{
    let langStore =useIndexStore()
    let LangDic=langStore.Lang.LangDataDic
    if(LangDic[K]){
        return LangDic[K]
    }
    return K
}

//设置或者变更语言类型
export  function SetLangType(LangType:string){
    let langStore =useIndexStore()
    let data =LangData
    data.push(...KeyLangData)
    langStore.Lang.LangDataDic={}
    for (let i = 0; i < data.length; i++) {
        let item=data[i]
        if(item[LangType]){
            langStore.Lang.LangDataDic[item["K"]]=item[LangType]
        }
    }
}

//获取键盘按键对应的字符串（多个）
export function GetLangKbs(keys:Array<number>):string{
    let lang=""
    for (let i = 0; i < keys.length; i++) {
        lang += GetLangKb(keys[i])
        if(i!= keys.length-1){
            lang +="+"
        }
    }
    return lang
}


export function GetLangKbStr(keys:string):string{
    let codes =keys.split("+").map(s=>parseInt(s))
    return GetLangKbs(codes)
}
//获取键盘按键对应的字符串（1个）
export function GetLangKb(k :number){
    return GetLang(`key_${k}`)
}


//获取键盘按键名称
export function GetLangMouse(k:number){
    return GetLang(`mouse_${k}`)
}
